package com.yuntian.service.Impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yuntian.Dto.NotePageQueryDto;
import com.yuntian.entity.Note;
import com.yuntian.entity.Product;
import com.yuntian.mapper.NoteMapper;
import com.yuntian.result.PageResult;
import com.yuntian.service.NoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NoteServiceImpl implements NoteService {

    @Autowired
    private NoteMapper noteMapper;

    //分类列表
    public PageResult list(NotePageQueryDto notePageQueryDto){
        PageHelper.startPage(notePageQueryDto.getPage(),notePageQueryDto.getPageSize());
        Page<Note> page = noteMapper.selectList(notePageQueryDto);
        long total = page.getTotal();
        List<Note> result = page.getResult();
        return new PageResult(total,result);

    }

    public void insertNote(Note note){
        note.setNoteCreate(LocalDateTime.now());
        noteMapper.insertNote(note);
    }

    public void updateNote(Note note){
        note.setNoteUpdate(LocalDateTime.now());
        noteMapper.updateNote(note);
    }

    public void deleteNote(Integer noteId){
        noteMapper.deleteNote(noteId);
    }

}
